{-# OPTIONS_GHC -XRecordWildCards #-}
module Main (main) where

import XI.Directory.WS.ProxyWSDL
import XI.Directory.WS.Types
import XI.Directory.WS.ParseWSDL
import System.Directory
import Control.Monad
import Data.List
import qualified Data.Map as Map

main = do
	p <- getCurrentDirectory
	setCurrentDirectory wsdlRoot
	s <- getDirectoryContents "." >>= filterM doesDirectoryExist >>= return . map (wsdlRoot ++) . filter (`notElem` [".", "..", ".svn"])
	setCurrentDirectory p
	mapM (\x -> do
		y <- print x >> parseWSDL x
		maps <- putStr "\n" >> print (wsdName y) >> catch (readFile $ wsdName y ++ ".map") (const $ return "")
		writeFile (wsdName y ++ ".map.sav") maps
		y' <- return . setAliases y . map read . lines $ maps
		writeFile (wsdName y' ++ ".map") . unlines . map show . getAliases $ y'
		writeFile (wsdName y' ++ ".hs") $ gen_proxy y'
		) s
	
wsdlRoot = "..\\doc\\wsdl\\"

